Ext.BLANK_IMAGE_URL = 'extjs/resources/images/default/s.gif';

Ext.onReady(function(){
    //菜单树
    mainTreePanel = new Ext.tree.TreePanel({
        width: 180,
        region: 'west',
        rootVisible: false,
        margins: '5, 0, 5, 5',
        root: {},
        loadMask: true,
        loader: {
            url: 'data/data_menu_tree.json'
        },
        tbar: {
            xtype: 'toolbar',
            items: [{
                xtype: 'button',
                icon: 'images/expand-all.gif'
            }, '-', {
                xtype: 'button',
                icon: 'images/collapse-all.gif'
            }, '->', {
                xtype: 'button',
                icon: 'extjs/resources/images/default/layout/collapse.gif',
				handler: function(){
					mainTreePanel.collapse(true);
				}
            }]
        },
        listeners: {
            load: function(n){
                n.expand(true, false);
            },
            click: function(n){
                var pkg = n.attributes.pkg;
                var uid = n.attributes.uid;
                if (!pkg || !uid) {
                    return;
                }
                var ui = Ext.getCmp(uid);
                if (ui) {
                    mainTabPanel.activate(ui);
                }
                else {
                    var fn = function(o, pkg){
                        var a = pkg.split(".");
                        if (a.length == 1) {
                            return o[a[0]];
                        }
                        else {
                            var t = o[a[0]];
                            if (t) {
                                a.shift();
                                return arguments.callee(t, a.join('.'));
                            }
                            else {
                                return;
                            }
                        }
                    }(window, pkg);
                    if (fn) {
                        ui = fn(uid);
                        mainTabPanel.add(ui);
                        mainTabPanel.activate(ui);
                    }
                }
            }
        }
    });
    //选项卡面板
    mainTabPanel = new Ext.TabPanel({
        activeTab: 0,
        region: 'center',
        margins: '5',
        items: [{
            xtype: 'panel',
            title: '<span style="color:#FF0000;">主页</span>'
        }]
    });
    //页面视图
    viewport = new Ext.Viewport({
        layout: 'border',
        items: [{
            xtype: 'box',
            region: 'north',
            height: 40,
            border: false,
            style: 'background: url(images/hd-bg.gif) repeat-x 0 0;'
        }, mainTreePanel, mainTabPanel]
    });
});
